<?php
namespace Home\Controller;
use Think\Controller;

class OrderController extends Controller{
	public function orderList(){
		$uid=$_SESSION["uid"];
		//$where["uid"]=$uid;
		$res = M('order')->where(array("uid"=>"{$uid}"))->order("ordtime desc")->select();
		$re = M('order')->select();
		$dfk = M('order')->where(array("uid"=>"{$uid}","ordnow"=>"2"))->count();
		$dfh = M('order')->where(array("uid"=>"{$uid}","ordnow"=>"3"))->count();
		$dsh = M('order')->where(array("uid"=>"{$uid}","ordnow"=>"4"))->count();
		$dpj = M('order')->where(array("uid"=>"{$uid}","ordnow"=>"5"))->count();
		foreach($re as $v){
			$pro[] = json_decode($v["pro"],true);
		}
		$this->assign("res",$res);
		$this->assign("pro",$pro);
		$this->assign("dfk",$dfk);
		$this->assign("dfh",$dfh);
		$this->assign("dsh",$dsh);
		$this->assign("dpj",$dpj);
		$this->display();
	}
	
	public function ordnowSave(){
		$oid = I("get.oid");
		$res = D('order');		
		$r = array();
		if($res->where(array("ordid"=>"{$oid}"))->save(array("ordnow"=>"6"))){
			$r['status']=true;
		}else{
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	}

	public function orderDel(){
		$oid = I("get.oid");
		$res = D('order');		
		$r = array();
		if($res->where(array("ordid"=>"{$oid}"))->delete()){
			$r['status']=true;
		}else{
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	}

	public function orderSure(){
		$oid = I("get.oid");
		$res = D('order');		
		$r = array();
		if($res->where(array("ordid"=>"{$oid}"))->save(array("ordnow"=>"5"))){
			$r['status']=true;
		}else{
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	}

	public function comment(){
		$id = I("get.id");
		$res = M("order")->where("id='{$id}'")->select();
		$shu = count($res);
		$this->assign("res",$res);
		$this->assign("shu",$shu);
		$this->display();
	}

	public function docomment(){
		$color = I("post.color");
		$size = I("post.size");
		$tc = I("post.tc");
		$ordid = I("post.ordid");
		$pid = I("post.pid");
		//print_r($pid);
		$content = I("post.rateContents");
		//print_r($content);
		foreach($content as $k=>$v){
			$arr["pid"] = $k;
			$arr["content"] = $v;
			$arr["goods_size"] = $size;
			$arr["goods_color"] = $color;
			$arr["goods_tc"] = $tc;
			$arr["uid"] = $_SESSION["uid"];
			$arr["uname"] = $_SESSION["uname"];
			$arr["add_time"]=time();
			$res = M("comment")->add($arr);
			
		}
		if($res){
				M("order")->where("ordid='{$ordid}'")->save(array("ordnow"=>"7"));
				$this->success('评价成功',U('Order/orderList'),2);
			}else{
				$this->error('评价失败',U('comment'),2);
			}

	}
}